//
//  ErandChangeApproveDetailViewController.m
//  KIASupervisory
//
//  Created by tan_xin on 14-8-18.
//  Copyright (c) 2014年 MyCompany. All rights reserved.
//

#import "ErandChangeApproveDetailViewController.h"

@interface ErandChangeApproveDetailViewController ()

@property (weak, nonatomic) IBOutlet UILabel *ccmdLbl;
@property (weak, nonatomic) IBOutlet UILabel *ccddLbl;
@property (weak, nonatomic) IBOutlet UILabel *jxsNameLbl;
@property (weak, nonatomic) IBOutlet UILabel *jxsCodeLbl;
@property (weak, nonatomic) IBOutlet UILabel *changeReasonLbl;


@end

@implementation ErandChangeApproveDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    self.title = @"出差变更明细";
    self.showLeftBtn = YES;
    self.showRightBtn = NO;
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
    
    [self.leftBtn setBackgroundImage:[UIImage imageNamed:@"Navigationbar_btn_返回_n.png"] forState:UIControlStateNormal];
    [self.leftBtn setBackgroundImage:[UIImage imageNamed:@"Navigationbar_btn_返回_p.png"] forState:UIControlStateHighlighted];
    
    [self getErandChangeApplyDetail];
}

- (void)leftNavItemAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)getErandChangeApplyDetail {
    if ([self.erandInfo count] > 0) {
        NSInteger erandID = [[self.erandInfo objectForKeyOrNil:@"id"] integerValue];
        if (erandID >= 0) {
            NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [NSString stringWithFormat:@"%d",erandID],@"id", nil];
            [self.networkManager requestWithMethod:showApplyByChangeExamineDetailById parameter:param delegate:self];
            [self.HUD show:YES];
        }
    }
}

#pragma mark - NetworkManagerDelegate
- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFinishedWithResult:(id)data {
    [self.HUD hide:YES];
    
    if (methodId == showApplyByChangeExamineDetailById) {
        if ([data isKindOfClass:[NSDictionary class]]) {
            int code = [[data objectForKeyOrNil:@"code"] integerValue];
            if (code == 0) {
                if ([data count] > 0) {
                    id dataObject = [data objectForKeyOrNil:@"data"];
                    if ([dataObject isKindOfClass:[NSDictionary class]]) {
                        NSDictionary *detailInfo = [dataObject objectForKeyOrNil:@"examineDetail"];
                        NSString *ccmd = [detailInfo objectForKeyOrNil:@"bgmd"];
                        NSString *ccdd = [detailInfo objectForKeyOrNil:@"ccdd"];
                        NSString *jxsName = [detailInfo objectForKeyOrNil:@"bgjxsmc"];
                        NSString *jxsCode = [detailInfo objectForKeyOrNil:@"bgjxsdm"];
                        NSString *reason = [detailInfo objectForKeyOrNil:@"bgly"];
                        
                        self.ccmdLbl.text = ccmd;
                        self.ccddLbl.text = ccdd;
                        self.jxsNameLbl.text = jxsName;
                        self.jxsCodeLbl.text = jxsCode;
                        self.changeReasonLbl.text = reason;
                        
                    }
                }
                
            } else {
                NSString *msg = [data objectForKeyOrNil:@"msg"];
                if ([msg  length] == 0) {
                    msg = @"出差变更申请详情获取失败，请稍后重试";
                }
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:msg
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
            }
        }
    }
}

- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFailedWithError:(NSError *)error {
    [self.HUD hide:YES];
    
    NSDictionary *errorInfo = error.userInfo;
    NSString *msg = [errorInfo objectForKeyOrNil:@"errorMsg"];
    if ([msg length] == 0) {
        msg = @"出差变更申请详情获取失败，请稍后重试";
        
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                    message:msg
                                                   delegate:nil
                                          cancelButtonTitle:@"确定"
                                          otherButtonTitles:nil];
    [alert show];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
